package com.ycw.servlet.laowei;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.HouseDao;
import com.ycw.dao.impl.HouseDaoImpl;
import com.ycw.pojo.House;

/**
 * Servlet implementation class UpdateHouse
 */
@WebServlet("/UpdateHouse")
public class HouseUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public HouseUpdateServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HouseDao hDao = new HouseDaoImpl();
		House house = new House(Integer.parseInt(request.getParameter("hid")), request.getParameter("hregion"),
				request.getParameter("hvillage"), request.getParameter("hunit"), request.getParameter("hroomnum"),
				request.getParameter("horientation"), request.getParameter("hrenovation"),
				Integer.parseInt(request.getParameter("hshuangqi")), request.getParameter("hfacilities"),
				Integer.parseInt(request.getParameter("hprice")), Integer.parseInt(request.getParameter("hstate")),
				request.getParameter("hpic"), request.getParameter("haddtime"));
		System.out.println("修改：" + house.toString());
		int i = hDao.updateHouseInfo(house);

		boolean f = false;
		if (i > 0) {
			f = true;
		}
		// 向前端发送JSON数据
		String resJSON = JSON.toJSONString(f);
		PrintWriter out = response.getWriter();
		out.write(resJSON);
		out.close();
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
